import os  

#
#    PROJECT 1A - GRADING APPLICATION - Helper Function
#
#    (this file contains functions used by main.py with allow the main
#        script to be more readable)


from config import *    # loads global variables and helper function from default_vars.py

# returns all directories in 'directory' whose name is 9 digits (i.e. SID number)
def listdirs(folder):
	dirs = []
	for d in (os.listdir(folder)):
        # only return directories that have a 9-digit name
		if (os.path.isdir(os.path.join(folder, d)) and re.match("^[0-9]{9}$",d)):
			dirs.append(d)
	return dirs

# returns a readable time format
# PARAMETER:	seconds	=> time in seconds
# RETURNS:	time as a string in hours, minutes, and seconds
def GetInHMS(seconds):
	hours = seconds / 3600
	seconds -= 3600*hours
	minutes = seconds / 60
	seconds -= 60*minutes
	if hours == 0:
		if minutes == 0:
			return "%02d secs" % (seconds)
		else:
			return "%02d mins %02d secs" % (minutes, seconds)
	else:
		return "%02d hrs %02d mins %02d secs" % (hours, minutes, seconds)
